package com.wantong.jianpu.customviews;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.wantong.jianpu.R;
import com.wantong.jianpu.beans.FaultDetailBean;

/**
 * @author PACY
 * @date 2022/4/25
 * description: 工单指派
 */
public class FaultAssignView extends LinearLayout {
    private FaultDetailBean.RecordsListDTO recordsBean;

    private TextView label_tv;//提示
    private LinearLayout content_lin;//详情数据UI

    private CommTextView user_ctv;//维修人员
    private CommTextView helpUser_ctv;//协助人员
    private CommTextView grade_ctv;//维修等级
    private CommTextView master_ctv;//指派人员
    private CommTextView time_ctv;//指派时间
    public FaultAssignView(Context context) {
        this(context,null);
    }

    public FaultAssignView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        /**
         * 加载布局  获取自定义属性
         */
        LayoutInflater.from(context).inflate(R.layout.fault_assign_view, this, true);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        initView();
    }

    private void initView(){
        label_tv=findViewById(R.id.label_tv);
        content_lin=findViewById(R.id.content_lin);
        user_ctv=findViewById(R.id.user_ctv);
        helpUser_ctv=findViewById(R.id.helpUser_ctv);
        grade_ctv=findViewById(R.id.grade_ctv);
        master_ctv=findViewById(R.id.master_ctv);
        time_ctv=findViewById(R.id.time_ctv);
        initData();
    }

    public void setData(FaultDetailBean.RecordsListDTO recordsBean){
        this.recordsBean=recordsBean;
        initView();
    }

    /**
     * 初始化数据
     */
    public void initData(){
        if(recordsBean!=null){
            if(recordsBean.isIfLast()){
                label_tv.setVisibility(VISIBLE);
                label_tv.setText(recordsBean.getLastText());
                content_lin.setVisibility(GONE);
            }else{
                label_tv.setVisibility(GONE);
                content_lin.setVisibility(VISIBLE);
                user_ctv.setContent(recordsBean.getRepairUserName());
                helpUser_ctv.setContent(recordsBean.getHelpUsersName());
                grade_ctv.setContent(recordsBean.getMaintainLevelName());
                master_ctv.setContent(recordsBean.getCreateUserName());
                time_ctv.setContent(recordsBean.getCreateTime());
            }
        }

    }
}
